#pragma once
#include "Base\AbstractRemoteProcedure.h"
#include <QObject>
#include "Network/Connection.h"
#include "Data\User.h"

namespace TC
{
	namespace Request
	{
		class TCCORE_EXPORT TeacherGroupsFetcher : public AbstractRemoteProcedure
		{
			Q_OBJECT
				Q_PROPERTY(QVariantList groups MEMBER groups)
		public:
			Q_INVOKABLE void fetch(uint idBegin, uint idEnd)
			{
	            if (status() == Status::Communicating)
	                return;
	            AbstractRemoteProcedure::get("evaluation/p2p/teacherGroups/fetch",
	            {
					{ "signature", Data::User::instance()->signature() },
					{ "idBegin", idBegin },
					{ "idEnd", idEnd },
	            });
			}
		protected:
			void onDataReady(QDataStream &stream) override
			{
				bool result;
	            stream >> result;
	            if (result)
				{
					QList<QVariantMap> vms;
					stream >> vms;
					groups.clear();
					for (QVariantMap &v : vms)
					{
						groups.append(v);
					}
					setOk();
	            }
	            else
	            {
	                setFailed();
	            }
			}
		private:
			QList<QVariant> groups;
		};
	}
}